package csu.web.credit_bank.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import csu.web.credit_bank.pojo.UserResource;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import csu.web.credit_bank.pojo.vo.ResourceVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserResourceMapper extends BaseMapper<UserResource> {
    @Select("SELECT r.*, u.username AS publisherName " +
            "FROM user_resources ur " +
            "LEFT JOIN resources r ON ur.resource_id = r.id " +
            "LEFT JOIN users u ON r.publisher_id = u.id " +
            "WHERE ur.user_id = #{userId}")
    IPage<ResourceVO> findJoinedResourcesByUserId(Page<ResourceVO> page, @Param("userId") String userId);
}